#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() 
{ 
	//TODO
	string name;
	vector<string> names;
	while ((cin>>name)&&(name.size()!=0)){
		names.push_back(name);
		if (cin.get()=='\n')break;
	}
	int longest=names[0].size(),shortest=names[0].size();
	vector<string> longest_names,shortest_names;
	longest_names.push_back(names[0]);
	shortest_names.push_back(names[0]);
	for (int i=1; i<names.size(); i++){
		if (names[i].size()>longest){
            longest=names[i].size();
            longest_names.clear();
            longest_names.push_back(names[i]);
        }else if (names[i].size()==longest){
            longest_names.push_back(names[i]);
        }
        if (names[i].size()<shortest){
            shortest=names[i].size();
            shortest_names.clear();
            shortest_names.push_back(names[i]);
        }else if (names[i].size()==shortest){
            shortest_names.push_back(names[i]);
        }
	}
	cout<<"longest: ";
	for (auto name:longest_names){
		cout<<name<<"\t";
	}
	cout<<endl<<"shortest: ";
    for (auto name:shortest_names){
		cout<<name<<"\t";
	}
	cout<<endl;
    
	return 0; 
}
